package com.tongtech.space.common.configs;

import com.tongtech.space.common.filter.FilterDemo;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 拦截器配置类
 *
 * @author jinjiayu
 * @since 2021/2/3
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<FilterDemo> filterBeanDemo() {
        FilterRegistrationBean<FilterDemo> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new FilterDemo());
        //配置过滤规则
        filterRegistrationBean.addUrlPatterns("/*");
        //设置init参数
        filterRegistrationBean.addInitParameter("name","过滤器demo");
        //设置过滤器名称
        filterRegistrationBean.setName("filterDemo");
        //执行次序,当配置多个过滤器实例时需要设置此参数,否则按照Bean的加载顺序来决定
        filterRegistrationBean.setOrder(1);

        return filterRegistrationBean;
    }
}
